<tpl> include file='sys_config.head.html' </tpl>
<link href="<tpl> $site_url </tpl>/js/jquery/ui.theme.css" rel="stylesheet" type="text/css" />
<div id="doc3">
	<div id="yui-main">
		<div class="yui-g">
 			<div id="divinbox">
				<div class="gtlbar">
					<div class="gtlbar-left"><tpl> $langMessageLetterGroupSend </tpl> &gt;&gt; <tpl> $langMessageAdd </tpl></div>
				</div>
				<div class="ctge">
					<div class="ctge-1">
						<form id="form_add" name="form_add" method="post" action="message.manage.php">
						<input type="hidden" name="action" value="save_message" />
						<div class="ctge-1-1">
							<table cellSpacing="0" cellPadding="0" class="fct" border="0">
								<tr>
									<th>标题:</th>
									<td><input name="title" id="title" class="fct-input" type="text" maxlength="40" /></td>
								</tr>
								<tr>
									<th>发送对象:</th>
									<td>
										<input type="radio" name="sendobj" value="1" checked onclick="send_message(this.value)">所有员工&nbsp;&nbsp;
										<input type="radio" name="sendobj" value="2" onclick="send_message(this.value)">指定员工&nbsp;&nbsp;
										<span style="display:none;" id="span_receive_name">
											<input name="system_receive_name" class="fct-input" type="text" />（最多可填写10个员工，多个员工名用逗号分割）
										</span>
									</td>
								</tr>
								<tr>
									<th><tpl> $langMessageContent </tpl>:</th>
									<td>
										<tpl>php</tpl>
											include_once('../classes/resource/editor/editor.class.php');
											$editor=new editor('content');
											$editor->Value='';
											$editor->BasePath='../classes/resource/editor';
											$editor->Height=460;
											$editor->Width=621;
											$editor->AutoSave=false;
											$editor->Create();
										<tpl>/php</tpl>
									</td>
								</tr>
								<!--<tr>
									<th><tpl> $langMessageWhetherAllowDel </tpl>:</th>
									<td><tpl> $system_message_delete </tpl></td>
								</tr>-->
							</table>
						</div>
						<div class="bth-ct">
							<div class="bth-pl">
								<input class="bthl" value="发送" type="submit" />
								<input type="button" class="bthl" value="返回" onclick="location.href='message.manage.php?action=list'" />
							</div>
						</div>
					</form>
					</div>
				</div>	
			</div>
		</div>
	</div>
</div>
<div id="question" class="loding-1" style="display:none;">
	
</div>
<input type="hidden" name="loop_num" id="loop_num" value="0" /> <!-- loop number -->
<tpl> include file='sys_config.js.html' </tpl>
<script src="<tpl> $site_url </tpl>/js/jquery/ui.datepicker.js"></script>
<script src="<tpl> $site_url </tpl>/js/jquery/jquery.blockUI.js"></script>
</body>
</html>
<script>
//show blockUI
var question = $('#question')[0];
function show_block(){
	$.blockUI(question, { width: '273px',height: '100px' });
}

//close block
function close_block(){
	$.unblockUI();
}

$(document).ready(function(){

	$('#end_date').datepicker({
		dateFormat:'yy-mm-dd',
		changeMonth: true,
		changeYear: true
	});
	$("#form_add").validate({
		errorClass: "wrong",
		rules: {
			title: {required:true}
		},
		messages: {
			title: {required:"<tpl> $errMessageTitle </tpl>"}
		},
		submitHandler: function(){
			submit_send();
		}
	});
});

function submit_send(){
	show_block();
	$('#question').html('<h3><tpl> $langMessageSendDoNow </tpl></h3><br />');
	send();
}
function send(){
	var loop_num = $('#loop_num').val();
	var title = $('#title').val();
	var content = $('#content').val();
	var system_message_object = $("input[@type=radio][@name='system_message_object'][@checked]").val();
	var system_receive_name = $("input[@name='system_receive_name']").val();
	var system_message_delete = $("input[@type=radio][@name='system_message_delete'][@checked]").val();
	var end_date = $('#end_date').val();
	$.ajax({
		url: "message.manage.php",
		data: 'action=save_message&loop_num='+loop_num+'&title='+title+'&content='+content+'&system_message_object='+system_message_object+'&system_receive_name='+system_receive_name+'&system_message_delete='+system_message_delete+'&end_date='+end_date,
		type: 'post',
		dataType: "json",
		success: function(msg){
			$('#question').html("<h3><tpl> $langMessageSendDoNow </tpl></h3><br />"+msg.message);
			// succ
			if(msg.type == 1){
				//loop num ++
				$('#loop_num').val(parseInt($('#loop_num').val())+1);
				send();
			}
			if(msg.type == 0){
				$('#loop_num').val(0);
				alert(msg.message);
				// close block
				//close_block();
				window.location='message.manage.php?action=list';
			}
			if(msg.type == 2){
				alert(msg.message);
				// close block
				close_block();
			}
		},
		error :function(){
			alert('<tpl> $langMessageSendLost </tpl>');
			// close block
			close_block();
		}
	});
	return false;
}

function send_message(str){
	if(str == '2'){
		$('#span_receive_name').css('display','');
	}else{
		$('#span_receive_name').css('display','none');
	}
}

function send_delete(str){
	if(str == '0'){
		$('#send_delete').css('display','');
	}else{
		$('#send_delete').css('display','none');
	}
}
</script>